#pragma once
#include <iostream>
#include <pthread.h>
#include <string>
#include <ctime>

static int num = 1;
template<class T>
class Thread
{
typedef void (*CallBack_t)(T);

public:
    void callback()
    {
        _cb(_args);

    }
    static void* Rountine(void* arg)
    {
        Thread* This = static_cast<Thread*>(arg);
        This->callback();
        return nullptr;
    }
    Thread(CallBack_t cb, T args):_cb(cb),_args(args)
    {
        _name = "thread-" + std::to_string(num++);
        _start_timestamp = time(nullptr);
        _isrunning = true;
        pthread_create(&_tid, nullptr, Rountine, this);
    }
    void Join()
    {
        pthread_join(_tid, nullptr);
        _isrunning = false;
    }
    std::string Getname()
    {
        return _name;
    }
    uint64_t GetStartTime()
    {
        return _start_timestamp;
    }
    bool IsRun()
    {
        return _isrunning;
    }
    ~Thread()
    {}
private:
    pthread_t _tid;
    CallBack_t _cb;
    T _args;
    std::string _name;
    uint64_t _start_timestamp;
    bool _isrunning;
};